package com.dat255.tentatime.testGUI;

import android.test.ActivityInstrumentationTestCase2;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.dat255.tentatime.LoginActivity;

public class TestLoginGUI extends ActivityInstrumentationTestCase2<LoginActivity> {

	//Variables
	private LoginActivity mLoginActivity;
	private TextView tvAdmin;
	private TextView tvPassword;
	private EditText etAdmin;
	private EditText etPassword;
	private Button bLogin;
	private String resourceStringAdmin;
	private String resourceStringPassword;
	private String resourceStringHintAdmin;
	private String resourceStringHintPassword;
	private String resourceStringButtonName;
	
	public TestLoginGUI() {
		super("com.dat255.tentatime", LoginActivity.class);
	}
	@Override
	protected void setUp() throws Exception {
		super.setUp();
		//Activate touchmode
		setActivityInitialTouchMode(true);
		//Get Activity
		mLoginActivity = this.getActivity();
		//Initialize Components
		tvAdmin = (TextView) mLoginActivity.findViewById(com.dat255.tentatime.R.id.tvAdmin);
		tvPassword = (TextView) mLoginActivity.findViewById(com.dat255.tentatime.R.id.tvPassword);
		etAdmin = (EditText) mLoginActivity.findViewById(com.dat255.tentatime.R.id.etAdmin);
		etPassword = (EditText) mLoginActivity.findViewById(com.dat255.tentatime.R.id.etPassword);
		bLogin = (Button) mLoginActivity.findViewById(com.dat255.tentatime.R.id.bLogin);
		//Set resources
		resourceStringAdmin = "Admin";
		resourceStringPassword = "Password";
		
		resourceStringHintAdmin = mLoginActivity.getString(com.dat255.tentatime.R.string.hintAdmin);
		resourceStringHintPassword = mLoginActivity.getString(com.dat255.tentatime.R.string.hintPassword);
		resourceStringButtonName = mLoginActivity.getString(com.dat255.tentatime.R.string.titleLogin);
		
	}
	/**
	 * Test that all components have been setup correctly
	 */
/*	public void testPreconditions() {
		assertNotNull(tvAdmin);
		assertNotNull(tvPassword);
		assertNotNull(etAdmin);
		assertNotNull(etPassword);
		assertNotNull(bLogin);
	}
*/
	/**
	 * Test TextView components, if they exists are visible and
	 * got the correct name
	 */
	public void testTextView() {
		//Check if component exists
		assertNotNull(tvAdmin);
		assertNotNull(tvPassword);
		//Check if component is visible on the screen
		assertTrue(tvAdmin.isShown());
		assertTrue(tvPassword.isShown());
		//Check if component got correct name
		assertEquals(resourceStringAdmin, tvAdmin.getText());
		assertEquals(resourceStringPassword, tvPassword.getText());
	}
	/**
	 * Test EditView components, if they exists are visible and
	 * got the correct name
	 */
	public void testEditText() {
		//Check if component exists
		assertNotNull(etAdmin);
		assertNotNull(etPassword);
		//Check if component is visible on the screen
		assertTrue(etAdmin.isShown());
		assertTrue(etPassword.isShown());
		//Check if component got correct hint
		assertTrue(resourceStringHintAdmin.equals(etAdmin.getHint()));
		assertTrue(resourceStringHintPassword.equals(etPassword.getHint()));
	}
	/**
	 * Test Button components, if the exists are visible and
	 * got the correct name
	 */
	public void testButtons() {
		//Check if component exists
		assertNotNull(bLogin);
		//Check if component is visible on the screen
		assertTrue(bLogin.isShown());
		//Check if component is clickable
		assertTrue(bLogin.isClickable());
		//Check if component got correct name
		assertTrue(resourceStringButtonName.equals(bLogin.getText()));
	}
}
